home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_100
/
193_01
/
backup.c
< prev
next >
Wrap
Text File
|
1985-11-13
|
17KB
|
354 lines
/*-----------------------------------------------------------------*/
/* PROGRAMME ==> backup.c */
/* Will back up any files which don't have the archive bit */
/* ( = t3) already set. */
/* VERSION: 1.3 Written: 13th July, 1986 */
/* ------- ------- Phil. E. Cogar */
/* */
/* Note: It uses an 8K buffer to do the file transfers */
/* ---- */
/* Usage is - */
/* backup [d1] [d2] */
/* */
/* where, "d1" and "d2" are drive names. */
/* */
/* This programme uses the CP/M functions - */
/* */
/* 15 open file */
/* 16 close file */
/* 17 search first */
/* 18 search next */
/* 19 erase file */
/* 26 set DMA address */
/* 30 set file attributes */
/* which will be found in the file DEFF3 and which will be added */
/* automatically to the "COM" file when you use CLINK. */
/* */
/* to do the required work. */
/* Written by: Phil Cogar - July 12, 1986 */
/* ---------- */
/* Copyright 1986 - Cogar Computer Services Pty.Ltd. */
/*-----------------------------------------------------------------*/
#include <bdscio.h> /* NOTE: This programme is specific to */
/* ---- BDS 'C'. If you use a different */
/* C then you must change this line. */
#include <pec.h> /* Required for this file */
/*-----------------------------------------------------------------*/
#define SECTORS 64 /* To be used in 8K buffer, transfer_buf */
#define VERSION "1.3" /* Current version number */
char transfer_buf[SECTORS*128]; /* which is for the copy part */
/* of the programme. */
/*-----------------------------------------------------------------*/
main(argc,argv)
short argc;
char *argv[];
{
/* The defined values used in the programme */
/*-----------------------------------------------------------------*/
char fcb[36]; /* Use for the ambiguous file mask */
short drive1, drive2, d1, d2; /* The nominated drives. */
char name_buf[3200]; /* Use to hold the file names */
/* Note present limit of 100 */
char fcb1[36]; /* The file control blocks */
char fcb2[36]; /* used in the file_copy routine */
char dma[128]; /* The DMA buffer for CP/M to use */
char mode[4]; /* The file mode */
mode[0] = 'A'; /* I know it can be done more */
mode[1] = 'R'; /* elegantly, but this makes it */
mode[2] = 'C'; /* clear that mode = "ARC" */
mode[3] = '\0'; /* with NULL terminator. */
short count, file_count, i, j, k, n; /* counters */
short value; /* General purpose function return */
short offset; /* Used in recovering the names from the */
/* name_buf, where we store them. */
short pointer; /* Used in transferring data to-and-from */
/* the transfer buffer. */
/*-----------------------------------------------------------------*/
/* The programme proper starts here. */
/* First construct the ambiguous search mask for use in the */
/* CP/M "search first" and "search next" routines */
/*-----------------------------------------------------------------*/
fcb[0] = '\0'; /* Note: Drive not allocated yet */
for(i = 1; i < 12; i++)
fcb[i] = '?';
for(i = 12; i < 36; i++)
fcb[i] = '\0';
offset = file_count = 0; /* starting values */
pec_clear(); /* clear the screen to start */
sign_on(); /* and put sign-on message */
/*-----------------------------------------------------------------*/
/* Now set the DMA buffer for transfer of information to and from */
/* the nominated drives. This buffer will be used throughout */
/* the programme whenever a file is accessed. */
/*-----------------------------------------------------------------*/
set_dma(dma);
/*-----------------------------------------------------------------*/
/* The programme proper starts here. First see whether the two */
/* drive names have been entered. */
/*-----------------------------------------------------------------*/
if(argc < 3) /* check to see if both drive names given */
{
drive1 = mess1(drive1); /* and if not then we have */
drive2 = mess2(drive2); /* to ask for them */
}
else if(argc == 3)
{
drive1 = toupper(*argv[1]);
drive2 = toupper(*argv[2]);
}
else mess3(); /* Otherwise you've screwed up somehow. */
/*-----------------------------------------------------------------*/
/* Now check to see whether valid drive names were entered. */
/* This programme only recognises drives A, B, C and D. If you */
/* have other drives change "check_drive" to suit. */
/*-----------------------------------------------------------------*/
check_drive(drive1);
check_drive(drive2);
/*-----------------------------------------------------------------*/
/* For the programme to work the drive names have to be different */
/* so now check that they are, else quit. */
/*-----------------------------------------------------------------*/
if(drive1 == drive2)
mess4();
/*-----------------------------------------------------------------*/
/* Now convert the drive names to CP/M format and use the search */
/* first and search next functions to collect those names where */
/* the t3 character doesn't have bit 7 set. Save these names */
/* into the name buffer */
/*-----------------------------------------------------------------*/
d1 = drive1 - 'A' + 1; /* Convert drives to CP/M format */
d2 = drive2 - 'A' + 1;
fcb[0] = d1; /* Put FROM drive into search mask then */
/* call the search first routine */
if((i = search_first(fcb)) != 255)
{
count = save_name(i, dma, name_buf, offset);
file_count = file_count + count;
if(count)
offset = offset + 32;
}
else mess5();
while((i = search_next()) != 255) /* Now do search next */
{
count = save_name(i, dma, name_buf, offset);
file_count = file_count + count;
if(count)
offset = offset + 32;
}
/*-----------------------------------------------------------------*/
/* Now check the name buffer and see if any files were found to */
/* copy. If not then quit. */
/*-----------------------------------------------------------------*/
if(file_count == 0)
mess6();
/*-----------------------------------------------------------------*/
/* If we get to here then there are some files to be archived so */
/* we can now start to copy these across to the back-up drive. */
/*-----------------------------------------------------------------*/
printf("\n\nStart of copying\n");
printf("----------------\n\n");
offset = 0; /* SüÄü